<template>
    <rx-layout>
        <div slot="center" style>
            <rx-fit>
                <div slot="toolheader" foldheader="true" foldbtn="false" border="false">
                    <div class="table-operator">
                        <rx-button alias="formWordTemplateAdd"
                                   :butn-icon="'plus'"
                                   :butn-type="'primary'"
                                   :show-no-right="true" @click="add">
                            {{$ti18('rxList.newBtn',"新建")}}
                        </rx-button>
                        <rx-button alias="formWordTemplateEdit" :butn-icon="'edit'" :butn-type="'primary'"
                                   v-if="editEnable && selectedRowKeys.length ==1"
                                   :show-no-right="false" @click="editOne(selectedRows[0])">
                            {{$ti18('rxList.editBtn',"编辑")}}
                        </rx-button>
                        <rx-button alias="formWordTemplateDelete" :butn-icon="'delete'" :butn-type="'danger'"
                                   v-if="removeEnable && selectedRowKeys.length > 0"
                                   :show-no-right="true" @click="delByIds(selectedRowKeys)">
                            {{$ti18('rxList.delBtn','删除')}}
                        </rx-button>
                    </div>
                    <span class="search-btn-box">
                        <span class="search-btn" @click="searchshow"><i class="iconfont iconguolv"></i>{{$ti18('rxList.leachBtn','过滤')}}</span>
                    </span>
                </div>
                <div slot="searchbar" btnalign="right" v-if="fitSearch" @search="search" @cancel="cancel"
                     @close="close">
                    <a-form-item :label="i18n('form.templateName','模板名称')">
                        <a-input :placeholder="i18n('form.templateName','请输入名称','input')" v-model="queryParam.Q_TEMPLATE_NAME__S_LK" />
                    </a-form-item>
                </div>
                <rx-grid
                    ref="table"
                    :allowRowSelect="true"
                    :multiSelect="true"
                    :columns="columns"
                    :defaultPageSize="10"
                    url="/api-form/form/core/formWordTemplate/query"
                    :queryParam="queryParam"
                    data-field="result.data"
                    :pageSizeOptions="['10','30','40']"
                    id-field="id"
                    @selectChange="onSelectChange"
                >
                    <span slot="mode" slot-scope="{ text, record }">
                        <a-tag :color="modeMap[text].color">
                          <span>{{ modeMap[text].text }}</span>
                        </a-tag>
                    </span>
                    <span slot="action" slot-scope="{ text, record }" class="actionIcons">
                        <span @click.stop="editOne(record)">
                            {{$ti18('rxList.editBtn',"编辑")}}
                        </span>
                        <span  @click.stop="delByIds([record.id])">
                            {{$ti18('rxList.delBtn','删除')}}
                        </span>
                    </span>
                </rx-grid>
            </rx-fit>
        </div>
    </rx-layout>
</template>

<script>
import FormWordTemplateApi from '@/api/form/core/formWordTemplate'
import FormWordTemplateEdit from './FormWordTemplateEdit'
import {BaseList, RxFit, RxGrid, Util} from "@lowcode/jpaas-common-lib";

export default {
    name: 'FormWordTemplateList',
    mixins: [BaseList],
    components: {
        RxFit
    },
    props:["boDefId","boDefName"],
    data() {
        return {
            columns: [
                {
                    title: this.$ti18('rxList.index','序号'),
                    type: 'indexColumn',
                    width: 50,
                    dataIndex: 'serial',
                    scopedSlots: {customRender: 'serial'}
                },
                {title: this.i18n('form.templateKey','模板主键'), dataIndex: 'id', width: 100},
                {title: this.i18n('form.templateName','模板名称'), dataIndex: 'templateName', width: 100},
                {title: this.i18n('form.mode','模式'), dataIndex: 'mode', width: 100, scopedSlots: {customRender: 'mode'}},
                {title: this.i18n('form.fileName','文件名'), dataIndex: 'fileName', width: 100},
                {title: this.$ti18('rxList.action','操作'), width: 100, dataIndex: 'action', scopedSlots: {customRender: 'action'},size:3}
            ],
            component: FormWordTemplateEdit,
            comment: this.i18n('list.comment','表单Word模板'),
            widthHeight: ['800px', '400px'],
            fitSearch: false,
            modeMap: {
                "on-line": {color: 'green', text: this.i18n('modeMap.online','在线')},
                "off-line": {color: 'blue', text: this.i18n('modeMap.offline','离线')},
            },
        }
    },
    created() {
        this.queryParam.Q_BO_ID__S_EQ=this.boDefId?this.boDefId:"";
    },
    methods: {
        cancel(){
            this.queryParam['Q_TEMPLATE_NAME__S_LK'] = '';
            this.$refs['table'].loadData()
        },
        i18n(name,text,key){
            return this.$ti18(name,text,"wordTemplate",key);
        },
        delById(ids) {
            return FormWordTemplateApi.del({ids: ids.join(',')});
        },
        getListByParams(parameter) {
            return FormWordTemplateApi.query(parameter)
        },
        add(){
            var conf = {
                component: FormWordTemplateEdit,
                title: this.$ti18('rxList.newBtn','添加')+"-"+this.i18n('list.comment','表单Word模板'),
                urlType: 'Add',
                widthHeight: ['800px', '610px'],
                data: { boDefId: this.boDefId, boDefName:this.boDefName },
            };
            this.handleEdit(conf);
        },
        editOne(record) {
            var conf = {
                pkId: record.pkId,
                component: FormWordTemplateEdit,
                title: this.$ti18('rxList.editBtn',"编辑")+"-"+this.i18n('list.comment','表单Word模板'),
                urlType: 'Edit',
                widthHeight: ['800px', '600px'],
                data: {pkId:record.pkId, boDefId: this.boDefId, boDefName:this.boDefName },
            };
            this.handleEdit(conf);
        },
    }
}
</script>
<style scoped>

</style>

